package com.three.controller;


import com.baor.baseUtil.R;
import com.three.domain.Users;
import com.three.domain.role;
import com.three.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value="/userList")
    public R userList(@RequestBody Map<String, Object> map) {
        String keyword = (String) map.get("keyword");
        int pageIndex = (int) map.get("pageIndex");
        int pageSize = (int) map.get("pageSize");
        return userService.userList(keyword, pageIndex, pageSize);
    }
    @RequestMapping(value="/addUser")
    public R addUser(@RequestBody Users users) {
        return userService.addUser(users);
    }
    //删除用户
    @RequestMapping(value="/deleteUser")
    public R deleteUser(@RequestBody List<Integer> teacher_ids) {
        return userService.deleteUser(teacher_ids);
    }
    //修改用户
    @RequestMapping(value="/updateUser")
    public R updateUser(@RequestBody Users users) {
        return userService.updateUser(users);
    }

    @RequestMapping(value="/roleList")
    public R roleList() {
        return userService.roleList();
    }
    //添加角色
    @RequestMapping(value="/addrole")
    public R addRole(@RequestBody role role) {
        return userService.addRole(role);
    }
//    删除角色
    @RequestMapping(value="/delrole")
    public R delrole(@RequestBody role role) {
        Integer role_id = role.getRole_id();
        return userService.delRole(role_id);
    }
}
